package com.example.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

public class BacsiTB {
    DatabaseHelp databasehelp;
    public BacsiTB(Context context) {
        databasehelp = new DatabaseHelp(context);
    }
    public final static String CLASS_TABLE = "tbBacsi";
    public final static String CLASS_MABACSI = "maBacsi";
    public final static String CLASS_TENBACSI = "tenBacsi";
    public final static String CLASS_MAKHOA = "maKhoa";
    public static String ten ="abc";


    public Cursor getInforBacsi(String query) {

        Cursor cursor = databasehelp.selectQuery(query);
        if (cursor != null)
            cursor.moveToFirst();
        return cursor;
    }
    public void insertInforBacsi(String tenBacsi,String maKhoa) {
        ContentValues value = new ContentValues();
        value.put(CLASS_TENBACSI, tenBacsi);
        value.put(CLASS_MAKHOA, maKhoa);
        long kq = databasehelp.insert_table(CLASS_TABLE, value);
        if(kq == -1)
        {
            Log.e("SQL", "Loi Insert");
        }
        else
        {
            Log.e("SQL", "Thanh cong");
        }
    }
    public void updateInforBacsi(String tenBacsi,String maKhoa, String maBacsi) {
        ContentValues values = new ContentValues();
        values.put(CLASS_TENBACSI, tenBacsi);
        values.put(CLASS_MAKHOA, maKhoa);
        long kq = databasehelp.update_table(CLASS_TABLE, values, maBacsi, CLASS_MABACSI);
        if(kq < 0)
        {
            Log.e("SQL", "Loi Insert");
        }
        else
        {
            Log.e("SQL", "Thanh cong");
        }
    }
    public void updateMulInforBacsi(String tenBacsi,String maKhoa, String maBacsi) {
        ContentValues values = new ContentValues();
        values.put(CLASS_TENBACSI, tenBacsi);
        values.put(CLASS_MAKHOA, maKhoa);
        long kq = databasehelp.update_mul_table(CLASS_TABLE, values, CLASS_MABACSI+"=? AND " +CLASS_TENBACSI+"=?" , new String[]{maBacsi,tenBacsi});
        if(kq < 0)
        {
            Log.e("SQL", "Loi Insert");
        }
        else
        {
            Log.e("SQL", "Thanh cong");
        }
    }
    public void deleteInforBacsi(String maBacsi) {
        long kq = databasehelp.delete_table(CLASS_TABLE,CLASS_MABACSI,maBacsi );
        if(kq < 0)
        {
            Log.e("SQL", "Loi Insert");
        }
        else
        {
            Log.e("SQL", "Thanh cong");
        }
    }
}
